<template>
  <view class="isometric-container">
    <!-- 顶部导航：等距风格，白紫渐变 -->
    <view class="nav-bar">
      <text class="nav-title">健康管理平台</text>
    </view>

    <!-- 主体内容：等距布局的功能模块 -->
    <view class="main-content">
      <!-- 左侧：轮播与设备区 -->
      <view class="module left-module">
        <view class="swiper-device">
          <view class="device-carousel">
            <uv-swiper
              :list="swiperList"
              indicator
              indicatorMode="dot"
              circular
              height="220"
              radius="18"
              autoplay
              interval="3500"
              :showTitle="false"
            >
              <template #item="{ item }">
                <view class="carousel-item">
                  <image 
                    :src="item.url" 
                    mode="widthFix" 
                    class="carousel-image"
                  ></image>
                </view>
              </template>
            </uv-swiper>
          </view>
          <view class="sensor-display">
            <view class="sensor-item" v-for="(item, index) in sensors" :key="index">
              <view class="sensor-icon" :class="item.iconClass"></view>
              <text class="sensor-name">{{ item.name }}</text>
            </view>
          </view>
        </view>
      </view>

      <!-- 中间：功能网格区 -->
      <view class="module center-module">
        <view class="function-grid">
          <uv-grid :col="4" :border="false" customStyle="padding: 8px;">
            <uv-grid-item
              v-for="(item, index) in functionList"
              :key="index"
              @click="handleFunctionClick(item)"
              customStyle="transition: all 0.3s ease; border-radius: 12rpx; box-shadow: 0 4px 12px rgba(123, 44, 191, 0.1);"
            >
              <view class="grid-item-content" :class="index % 2 === 0 ? 'white-bg' : 'purple-bg'">
                <uv-icon 
                  :name="item.icon" 
                  size="18" 
                  :color="index % 2 === 0 ? '#6b7fd7' : '#ffffff'"
                ></uv-icon>
                <text class="grid-text" :class="index % 2 === 0 ? 'purple-text' : 'white-text'">{{ item.name }}</text>
              </view>
            </uv-grid-item>
          </uv-grid>
        </view>
      </view>

      <!-- 右侧：数据与操作区 -->
      <view class="module right-module">
        <view class="data-display">
          <view class="data-item" v-for="(item, index) in vitalData" :key="index">
            <text class="data-label">{{ item.label }}</text>
            <text class="data-value">{{ item.value }}</text>
            <text class="data-unit">{{ item.unit }}</text>
          </view>
        </view>
        <view class="action-buttons">
          <view 
            class="action-btn" 
            v-for="(item, index) in actionButtons" 
            :key="index"
            @click="handleAction(item)"
          >
            <text class="btn-text">{{ item.name }}</text>
          </view>
        </view>
      </view>
    </view>

    <tabBar></tabBar>
  </view>
</template>

<script setup>
import { ref } from 'vue';

// 轮播图数据
const swiperList = ref([
  { url: '/static/health-banner1.png' },
  { url: '/static/health-banner2.png' },
  { url: 'https://picsum.photos/800/400?random=1' }
]);

// 传感器数据
const sensors = ref([
  { name: '心率传感器', iconClass: 'icon-heart' },
  { name: '血氧传感器', iconClass: 'icon-oxygen' },
  { name: '血压传感器', iconClass: 'icon-blood' },
  { name: '体温传感器', iconClass: 'icon-temperature' }
]);

// 功能列表
const functionList = ref([
  { name: '预约就诊', icon: 'calendar', path: '/pages/gongneng/appointment' },
  { name: '日程管理', icon: 'clock' },
  { name: '健康检测', icon: 'heart', path: '/pages/gongneng/HealthMonitor' },
  { name: '报告查询', icon: 'search',path:'/pages/gongneng/SearchReport' },
  { name: 'AI问诊', icon: 'chat', path: '/pages/gongneng/ChatWithAI' },
  { name: '健康档案', icon: 'file-text', path: '/pages/gongneng/healthFiles' },
  { name: '医疗报告', icon: 'file',path:'/pages/gongneng/healthReport' },
  { name: '在线问诊', icon: 'message',path:'/pages/gongneng/inquiry' }
]);

// 生命体征数据
const vitalData = ref([
  { label: '心率', value: '72', unit: '次/分' },
  { label: '血氧', value: '98', unit: '%' },
  { label: '血压', value: '120/80', unit: 'mmHg' },
  { label: '体温', value: '36.5', unit: '℃' }
]);

// 操作按钮
const actionButtons = ref([
  { name: '开始监测', action: 'start' },
  { name: '导出报告', action: 'export' },
  { name: '健康分析', action: 'analyze' },
  { name: '设置', action: 'settings' }
]);

// 原有逻辑保持不变
const tabValue = ref(0);
const dateColumns = ref([
  Array.from({ length: 12 }, (_, i) => ({ label: `${i + 1}月` })),
  Array.from({ length: 31 }, (_, i) => ({ label: `${i + 1}日` }))
]);
const picker = ref(null);

const handleFunctionClick = (item) => {
  if (item.action === 'openPicker') {
    picker.value.open();
  } else if (item.path) {
    uni.navigateTo({ url: item.path });
  } else {
    uni.showToast({ title: `点击了 ${item.name}`, icon: 'none' });
  }
};

const handleTabChange = (index) => {
  tabValue.value = index;
  const path = tabList.value[index].path;
  uni.switchTab({ url: path });
};

const onPickerConfirm = (e) => {
  const selected = e.value.map(item => item.label).join('-');
  uni.showToast({ title: `选择了 ${selected}`, icon: 'success' });
};

const onPickerCancel = () => {
  uni.showToast({ title: '取消选择', icon: 'none' });
};

const handleAction = (item) => {
  let toastMsg = '';
  switch (item.action) {
    case 'start':
      toastMsg = '开始健康监测';
      break;
    case 'export':
      toastMsg = '导出健康报告';
      break;
    case 'analyze':
      toastMsg = '生成健康分析';
      break;
    case 'settings':
      toastMsg = '进入设置页面';
      break;
  }
  uni.showToast({
    title: toastMsg,
    icon: 'none'
  });
};
</script>

<style scoped>
/* 全局容器：等距视角背景，浅紫渐变 */
.isometric-container {
  background: linear-gradient(180deg, #f5f0ff, #ffffff);
  min-height: 100vh;
  padding: 20px;
  flex-direction: column;
}

/* 顶部导航栏：等距风格，白紫渐变 */
.nav-bar {
  background: linear-gradient(135deg, #ffffff, #f5f0ff);
  border-radius: 12px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 30px;
  box-shadow: 0 4px 12px rgba(123, 44, 191, 0.1);
  /* flex-direction: column; */
}

.nav-title {
  color: #6b7fd7;
  font-size: 20px;
  font-weight: bold;
}

/* 主体内容布局：等距三列 */
.main-content {
  display: block;
  justify-content: space-between;
  
}

.module {
  background-color: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(123, 44, 191, 0.1);
  padding: 5px 5px;
  flex-direction: column;
  margin-bottom: 30px;
  
}

.left-module, .right-module {
  width: 100%;
  flex-direction: column;
  margin-bottom: 30px;
}

.center-module {
  width: 100%;
  flex-direction: column;
  margin-bottom:30px;
}

/* 左侧：轮播与传感器区 */
.swiper-device {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.device-carousel {
  border: 3px solid;
  border-image: linear-gradient(135deg, #ffffff, #7b2cbf) 1;
  border-radius: 18rpx;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(123, 44, 191, 0.15);
}

.carousel-item {
  width: 100%;
  height: 220px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #f5f0ff, #ffffff);
}

.carousel-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 12rpx;
}

.sensor-display {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
}

.sensor-item {
  background: linear-gradient(135deg, #2FCBFC, #9d4edd);
  border-radius: 8px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.sensor-item:active {
  transform: translateY(2px);
  box-shadow: 0 2px 8px rgba(123, 44, 191, 0.15);
}

.sensor-icon {
  width: 40px;
  height: 40px;
  margin-bottom: 8px;
  border-radius: 50%;
  background-color: #ffffff;
}

.sensor-name {
  color: #ffffff;
  font-size: 14px;
}

/* 中间：功能网格区 */
.function-grid {
  width: 100%;
}

.grid-item-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 6px;
  width: 100%;
  height: 100%;
  border-radius: 12rpx;
  transition: all 0.3s ease;
}

.white-bg {
  background-color: #ffffff;
}

.purple-text {
  color: #6b7fd7;
}

.purple-bg {
  background: linear-gradient(135deg, #7b2cbf, #9d4edd);
}

.white-text {
  color: #ffffff;
}

.uv-grid-item:active .grid-item-content {
  transform: translateY(2px);
  box-shadow: 0 2px 8px rgba(123, 44, 191, 0.15);
}

.uv-grid-item {
  padding: 8rpx !important;
}

.grid-text {
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.4;
  font-weight: 500;
}

/* 右侧：数据与操作区 */
.data-display {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
  margin-bottom: 20px;
}

.data-item {
  background: linear-gradient(135deg, #f5f0ff, #ffffff);
  border-radius: 8px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(123, 44, 191, 0.05);
}

.data-label {
  font-size: 14px;
  color: #6b7fd7;
  margin-bottom: 5px;
}

.data-value {
  font-size: 20px;
  font-weight: bold;
  color: #333333;
}

.data-unit {
  font-size: 14px;
  color: #888888;
}

.action-buttons {
  display: grid;
  grid-template-columns: 1fr;
  gap: 15px;
}

.action-btn {
  background: linear-gradient(135deg, #7b2cbf, #6b7fd7);
  border-radius: 8px;
  padding: 15px;
  text-align: center;
  transition: all 0.3s ease;
}

.action-btn:active {
  transform: translateY(2px);
  opacity: 0.9;
  box-shadow: 0 2px 8px rgba(123, 44, 191, 0.15);
}

.btn-text {
  color: #ffffff;
  font-size: 16px;
}

/* 轮播图指示器：白紫配色 */
.uv-swiper__indicator {
  bottom: 12px !important;
}

.uv-swiper__indicator--dot {
  width: 10rpx !important;
  height: 10rpx !important;
  margin: 0 5rpx !important;
  background-color: rgba(255, 255, 255, 0.8) !important;
}

.uv-swiper__indicator--dot.active {
  background-color: #7b2cbf !important;
  width: 28rpx !important;
  border-radius: 5rpx !important;
}
</style>